/*
 * @Descripttion:
 * @Author: 张正兴
 * @Date: 2022-03-28 15:59:08
 * @LastEditors: 张正兴
 */
// 灯光
import * as THREE from "three";

class LightMod {
  // 场景
  scene: any = {};

  constructor(scene?: any) {
    this.scene = scene;
  }

  /**
   * 平行光
   * @position 位置
   * @color 颜色
   * @luminance 强度
   */
  directionalLight(position: any, luminance = 1, color = "#ffffff") {
    const parallelLight = new THREE.DirectionalLight("#ffffff", luminance);
    parallelLight.position.set(position[0], position[1], position[2]);
    parallelLight.castShadow = true;
    parallelLight.name = "平行光"
    // const helper = new THREE.DirectionalLightHelper(parallelLight, 10);
    this.scene.add(parallelLight);
    // this.scene.add(helper);
  }

  /**
   * 射灯
   * @position 位置
   * @color 颜色
   * @luminance 强度
   */
  spotlight(position: any, luminance = 2, color = "#ffffff") {
    const pointLight = new THREE.PointLight(color, luminance, 300);
    pointLight.position.set(position[0], position[1], position[2]);
    pointLight.name = "射灯"
    return pointLight
  }

  /**
   * 点光源
   * @position 位置
   * @color 颜色
   * @luminance 强度
   * @range 范围
   */
  pointLight(position: any, color = "#ffffff", luminance = 1, range = 100) {
    const pointLight = new THREE.PointLight(color, luminance, range);
    pointLight.position.set(position[0], position[1], position[2]);
    this.scene.add(pointLight);
    const sphereSize = 2;
    const pointLightHelper = new THREE.PointLightHelper(pointLight, sphereSize);
    this.scene.add(pointLightHelper);
  }

  /**
   * @color 颜色
   * @luminance 强度
   */
  ambientLight(luminance = 0.1, color = "#ffffff") {
    const ambientLight = new THREE.AmbientLight(color, luminance);
    this.scene.add(ambientLight);
  }
}

export default LightMod;
